package com.it.archives.dao.provider;

import com.it.archives.model.User;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

public class UserProvider {

    private final String TBL_USER = "user";
    private final String col_user = "id,username,login_name as loginName,password";


    public String queryUserListByParam(User param) {
        SQL sql = new SQL().SELECT(col_user).FROM(TBL_USER);

        String id = param.getId();
        if (StringUtils.hasText(id)) {
            sql.WHERE("id = #{id}");
        }
        String name = param.getLoginName();
        if (StringUtils.hasText(name)) {
            sql.WHERE("login_name LIKE #{loginName}");
        }
        return sql.toString();
    }
}
